<template>
  <div>
    <el-dialog
      v-model="open"
      :close-on-click-modal="false"
      :title="title"
      append-to-body
    >
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="warning" @click="handleExport2">导出</el-button>
          <el-button type="primary" @click="handleExport3">导出订单信息（全）</el-button>
        </el-col>
      </el-row>
      <el-table
        v-loading="loading"
        border
        show-summary
        :summary-method="onSummary"
        :data="form"
        height="500px"
      >
        <el-table-column label="状态" align="center" prop="splittingStatus"></el-table-column>
        <el-table-column
          label="客户单号"
          align="center"
          prop="waybillNo"
          width="100"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="主转单号"
          align="center"
          prop="mainTransferOrderNo"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          label="类型"
          align="center"
          prop="goodsType"
          :formatter="(row) => dicts.getDictLabel({ dict: DictDirection.货物类型, value: row.goodsType })"
        ></el-table-column>
        <el-table-column
          label="收货实重"
          align="center"
          prop="receivingTotalWeight"
          width="80"
        ></el-table-column>
        <el-table-column
          label="收货材积重（方）"
          align="center"
          prop="receivingTotalWood"
          width="130"
        ></el-table-column>
        <el-table-column
          label="销售产品"
          align="center"
          prop="marketProducts"
          :formatter="(row) => dicts.getDictLabel({ dict: DictDirection.产品, value: row.marketProducts })"
        ></el-table-column>
        <el-table-column label="件数" align="center" prop="receivingTotal"></el-table-column>
        <el-table-column
          label="系统订单号"
          align="center"
          prop="orderNo"
          width="120"
          show-overflow-tooltip
        ></el-table-column>
      </el-table>
      <pagination
        v-show="total2 > 0"
        v-model:page="queryParams.pageNum"
        v-model:limit="queryParams.pageSize"
        :total="total2"
        @pagination="getList"
      />
      <div class="dialog-footer">
        <el-button type="info" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script lang="ts" setup>
import { ref, getCurrentInstance } from 'vue'
import { ElButton } from 'element-plus'
import { eTableSum } from '@/utils/index'
import { mergeOrderInfo } from '@/api/expressManager/outPutOrder'
import useDicts, { DictDirection } from '@/store/modules/dicts'

const dicts = useDicts()
dicts.setDicts(DictDirection.产品)
dicts.setDicts(DictDirection.货物类型)
const open = ref(false)
const title = ref(null)
const form = ref([])
const loading = ref(false)
const total2 = ref(null),
  {
    appContext: {
      config: {
        globalProperties: { $download },
      },
    },
  } = getCurrentInstance()
const queryParams = ref({
  pageSize: 10,
  pageNum: 1,
})
const onSummary = (params) => eTableSum(params, ['waybillNo', 'mainTransferOrderNo', 'goodsType', 'marketProducts', 'orderNo'])
const handleExport2 = () => {
  $download('order/deliveryMerge/exportWholeCabinet', rowss.value, `WholeCabinet_${ new Date().getTime() }.xlsx`)
}
const handleExport3 = () => {
  $download('order/deliveryMerge/ladingNosExport', rowss.value, `WholeCabinet_All_
  ${ new Date().getTime() }.xlsx`)
}
const getList = () => {
  const query = queryParams.value
  const body = idss.value
  console.log(rowss.value)
  
  mergeOrderInfo(query, body).then(res => {
    form.value = res.data
    total2.value = res.total
    loading.value = false
  }).catch(() => {
    loading.value = false
  })
}
const cancel = () => {
  open.value = false
}
const rowss = ref([])
const idss = ref([])
defineExpose({
  open,
  title,
  loading,
  getList,
  rowss,
  idss,
})
</script>